package com.beauty.dressing.module.mine.holder;

import android.content.Context;
import android.content.Intent;
import android.support.v4.content.ContextCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.beauty.dressing.R;
import com.beauty.dressing.common.base.BaseRecyclerViewHolder;
import com.beauty.dressing.common.bean.BaseBean;
import com.beauty.dressing.common.bean.LeaseBean;
import com.beauty.dressing.common.utils.Constants;
import com.beauty.dressing.module.mine.activity.HistoricalLeaseActivity;
import com.beauty.dressing.module.mine.activity.MyInRentActivity;
import com.beauty.dressing.module.mine.activity.WithdrawalActivity;
import com.beauty.dressing.rxandroid.api.ApiManager;
import com.xiaolanba.commonlib.fresco.FrescoUtil;

public class MyleaseHolder extends BaseRecyclerViewHolder<BaseBean> {
    private SimpleDraweeView goods_image;
    private TextView lease_name;
    private ImageView lease_btn;
    private TextView service_number;
    private TextView service_time;
    private TextView leased_time;
    private TextView lease_status;
    private LinearLayout rv_item;
    public MyleaseHolder(Context context, LayoutInflater inflater, ViewGroup viewGroup) {
        super(R.layout.my_lease_item, context, inflater, viewGroup);
    }


    @Override
    public void findView() {
        goods_image = itemView.findViewById(R.id.goods_image);
        lease_name = itemView.findViewById(R.id.lease_name);
        lease_btn = itemView.findViewById(R.id.lease_btn);
        service_number = itemView.findViewById(R.id.service_number);
        service_time = itemView.findViewById(R.id.service_time);
        leased_time = itemView.findViewById(R.id.leased_time);
        lease_status = itemView.findViewById(R.id.lease_status);
        rv_item = itemView.findViewById(R.id.rv_item);
    }

    @Override
    public void bindData(final BaseBean bean, int position) {
        if (bean instanceof LeaseBean) {
            switch (((LeaseBean) bean).getLeaase_status()) {
                case 1:
                    leased_time.setText(((LeaseBean) bean).getLease_days() + "天");
                    rv_item.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            mContext.startActivity(new Intent(mContext, MyInRentActivity.class).putExtra(Constants.ACTIVITYDATA, bean));
                        }
                    });
                    break;
                case 2:
                    lease_status.setText("当前状态");
                    if (((LeaseBean) bean).getStatus_name().equals("审核中")) {
                        leased_time.setTextColor(ContextCompat.getColor(mContext, R.color.main_color));
                    } else if (((LeaseBean) bean).getStatus_name().equals("退租失败")) {
                        leased_time.setTextColor(ContextCompat.getColor(mContext, R.color.red));
                    }
                    leased_time.setText(((LeaseBean) bean).getStatus_name());
                    rv_item.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            mContext.startActivity(new Intent(mContext, WithdrawalActivity.class).putExtra(Constants.ACTIVITYDATA, bean));
                        }
                    });
                    break;
                case 3:
                    lease_status.setText("当前状态");
                    leased_time.setText(((LeaseBean) bean).getStatus_name());
                    rv_item.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            mContext.startActivity(new Intent(mContext, HistoricalLeaseActivity.class).putExtra(Constants.ACTIVITYDATA, bean));

                        }
                    });
                    break;
                case 4:
                    lease_status.setText("当前状态");
                    leased_time.setText(((LeaseBean) bean).getStatus_name());
                    rv_item.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            mContext.startActivity(new Intent(mContext, HistoricalLeaseActivity.class).putExtra(Constants.ACTIVITYDATA, bean));

                        }
                    });
                    break;
            }
            FrescoUtil.loadImage(goods_image, ApiManager.HEAR_URL + ((LeaseBean) bean).getImage());
            lease_name.setText(((LeaseBean) bean).getLease_name());
            service_number.setText(((LeaseBean) bean).getOrder_number());
            service_time.setText("2018.03.03  12:00");

        }
    }
}
